package com.oocl.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.oocl.pojo.Merchant;
import com.oocl.pojo.MerchantApplyRecord;
import com.oocl.service.MerchantManager;
import com.oocl.service.factory.MerchantManagerFactory;

@WebServlet("/sec/history")
public class HistoryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MerchantManager merchantManager;
	private Logger logger = Logger.getLogger(HistoryServlet.class);
       
    public HistoryServlet() {
        super();
        merchantManager = MerchantManagerFactory.getInstance();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String mid = request.getParameter("mid");
		if(mid!=null){
			List<MerchantApplyRecord> history = merchantManager.findHistory(mid);
			if(!history.isEmpty()){
				request.setAttribute("history", history);
				request.getRequestDispatcher("../WEB-INF/views/history.jsp").forward(request, response);
				logger.info("check history record of merchant");
			}
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
